package arch.dao.impl.archive;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import arch.domain.archive.ArchiveDefinition;
import arch.domain.archive.Template;

public class ArchiveDefMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int i) throws SQLException {
		ArchiveDefinition archDef = new ArchiveDefinition();
		Template editTemp = new Template();
		Template printTemp = new Template();
		archDef.setId(rs.getInt("id"));
		archDef.setName(rs.getString("name"));
		if(rs.getInt("edit_template_id")!=0){
			editTemp.setId(rs.getInt("edit_template_id"));
			archDef.setEditTemplate(editTemp);
		}		
		if(rs.getInt("print_template_id")!=0){
			printTemp.setId(rs.getInt("print_template_id"));
			archDef.setPrintTemplate(printTemp);
		}		
		archDef.setRank(rs.getInt("rank"));
		archDef.setEnable(rs.getBoolean("enable"));
		archDef.setDescription(rs.getString("description"));
		return archDef;
	}

}
